package com.example.readdeploy.web;

import com.example.readdeploy.config.RemoteProperties;
import com.example.readdeploy.config.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.Set;

@RestController
public class PersonController {

    @Value("${person.userName}")
    private String userName;
    @Value("${person.age}")
    private int age;

    @Value("${test.array1}")
    private String[] testArray1;     // 不判断空

//    @Value("${test.array1:}")
//    private String[] testArray1;     // 判断空length = 0。


    @Value("#{'${test.list}'.split(',')}")
    private List<String> testList;  //不判断空

    @Value("#{'${test.list1}'.split(',')}")
    private List<Integer> testList1;

//    @Value("#{'${test.list:}'.split(',')}")
//    private List<String> testList;  //判断空  length=1  有一个“”元素
//
//    @Value("#{'${test.list:}'.empty ? null : '${test.list:}'.split(',')}")
//    private List<String> testList;   //判断空 null



    @Value("#{'${test.set:}'.empty ? null : '${test.set:}'.split(',')}")
    private Set<Integer> testSet;


    @Value("#{${test.map1}}")
    private Map<String,String> map1;


    @Autowired
    private User user;

    @Autowired
    RemoteProperties remoteProperties;

    @RequestMapping(value = "/get",method = RequestMethod.GET)
    public void findPerson(){

        System.out.println("姓名："+userName+"年龄："+age);
        System.out.println("数组："+testArray1);
        System.out.println("List: "+testList);
        System.out.println("List1: "+testList1);
        System.out.println("Set: "+testSet);
        System.out.println("Map: "+ map1);
//        System.out.println("User: "+ new User().toString());
        System.out.println("User: "+ user.toString());
        System.out.println("Properties: "+ remoteProperties.getTestname());
    }
}